package com.example.abc;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class dl extends AppCompatActivity {
    EditText yhm;
    EditText mima;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


      Button dl;
      Button zhuce;


        yhm = findViewById(R.id.userEditText);
        mima = findViewById(R.id.passwordEditText);
        dl = findViewById(R.id.loginBtn);
        zhuce = findViewById(R.id.regBtn);

        dl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user, password;

                user = yhm.getText().toString();
                password = mima.getText().toString();


                if (!glq.dl(getApplicationContext(), user, password)) {
                    Toast.makeText(dl.this, "账号或密码错误", Toast.LENGTH_SHORT).show();
                    return;
                }

                Intent intent = new Intent(dl.this, MainActivity.class);

                intent.putExtra("user", user);
                startActivity(intent);
            }
        });
        zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(dl.this, zc.class), 1);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (data == null) {
            return;
        }

        if (resultCode == 1) {
            yhm.setText(data.getStringExtra("user"));
            mima.setText(data.getStringExtra("password"));
        }
    }
}